package ch01;

import java.lang.reflect.Method;

/**
 * @author yang
 * @date 2024-03-29
 */
public class People <T extends Pet>{
    private T pet;

    public T getPet() {
        return pet;
    }

    public void setPet(T pet) {
        this.pet = pet;
    }

    public void shopping() throws Exception{
        Class<?> petClass = pet.getClass();
        Object petName = petClass.getMethod("getName").invoke(this.pet);
        System.out.println("带着 "+petName+" 逛街");

        try{
            Object load = petClass.getMethod("load");
            ((Method) load).invoke(this.pet);
        }catch (Exception e){
            System.out.println("不会叫");
        }
    }

    public static void main(String[] args) throws Exception {
        Bird pet = new Bird();
        People<Bird> zs = new People<>();
        zs.setPet(pet);
        zs.shopping();
    }
}
